package com.jhg.drgclinicalpathway.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jhg.drgclinicalpathway.domain.Pro2Cost;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface Pro2CostDao extends BaseMapper<Pro2Cost> {
    @Select({
            "<script>",
            "select format(a.发生时间,'yyyy-MM-dd') ts,类型A proType,c.属性 attr,c.名称 name,c.说明 proSubType,avg(a.金额) amount,SUM(数量) num from  VDCP_费用记录 a ",
            "left join LJ_临床路径项目明细 b on a.医保项目编码=b.项目编码 COLLATE Chinese_PRC_BIN",
            "left join V临床路径项目 c on b.项目ID=c.ID",
            "where  病人标识=#{id} and  属性!=1 and ISNULL(c.状态,0)=0 and  c.属性!=1",
            "group by 类型A,c.说明,format(a.发生时间,'yyyy-MM-dd'),c.属性,c.名称",
            "order by 类型A",
            "</script>"
    })
    public List<Map<String,Object>> findProTypeByPatId(String id);

    @Select({
            "<script>",
            "select format(a.发生时间,'yyyy-MM-dd') ts,类型A proType,c.名称 name,c.属性 attr,c.说明 proSubType,SUM(a.金额) amount,SUM(数量) num from VDCP_费用记录 a ",
            "left join LJ_临床路径项目明细 b on a.医保项目编码=b.项目编码 COLLATE Chinese_PRC_BIN",
            "left join V临床路径项目 c on b.项目ID=c.ID",
            "where  病人标识=#{id} and  属性!=1 and ISNULL(c.状态,0)=0 and  c.属性!=1 and 类型A='药品'",
            "group by 类型A,c.说明,format(a.发生时间,'yyyy-MM-dd'),c.属性,c.名称",
            "order by 类型A",
            "</script>"
    })
    public List<Map<String,Object>> findProTypeAndNameByPatId(String id);

    @Select({
            "select a.参考费用 price,b.说明 proSubType,类型A proType,b.名称 name from LJ_项目费用参考 a",
                    " left join V临床路径项目 b on a.项目ID=b.ID COLLATE Chinese_PRC_BIN" ,
                    "where b.说明 is not null"
    })
    public List<Map<String,Object>> proc2cost();


    /**
     * 病人基础项目
     * @param id
     * @return
     */
    @Select({
            "select 费用类别,医保项目编码,项目名称,费用属性,MAX(标准单价) 标准单价,SUM(金额) 金额,SUM(数量) 数量 from VDCP_费用记录",
            "where 病人标识=#{id} and 是否基础项目=1",
            "group by  费用类别,医保项目编码,项目名称,费用属性"
    })
    public List<Map<String,Object>> patBasicCostById(String id);


    @Select({
            "select 医保项目编码,项目名称,费用类别,费用属性,单位,费用等级,适用疾病,SUM(数量) 数量,SUM(金额) 金额 from VDCP_费用记录 where 病人标识=#{id}",
            "group by 医保项目编码,项目名称,费用类别,费用属性,单位,费用等级,适用疾病",
            "order by 费用类别"
    })
    public List<Map<String,Object>> costSummary(String id);
}
